package com.xpoint.backend.controller;

import com.xpoint.backend.common.R;
import com.xpoint.backend.entity.AddressBook;
import com.xpoint.backend.entity.User;
import com.xpoint.backend.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/login")
//    用户登录
    public R<User> userLogin(@RequestBody User user, HttpServletRequest request){
        return userService.userLogin(user,request);
    }

    @RequestMapping("/register")
//    用户注册
    public R<String> userRegister(@RequestBody User user){
        return userService.userRegister(user);
    }

    @GetMapping("/findUser")
//    查询用户
    public R<User> findUser(){
        return userService.findUser();
    }

    @PostMapping("/loginout")
//    退出登录
    public R<String> logout(HttpServletRequest request){
        request.getSession().removeAttribute("userId");
        return R.success("成功退出");
    }
}
